package database.in;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class ConnectDatabase {
	public static Connection makeConnection(){
		String url = "jdbc:mysql://localhost/mysql_study";
		String id = "root";
		String password = "1111";
		Connection con = null;
		try {
			Class.forName("com.mysql.jdbc.Driver");
			System.out.println("드라이버 적재 성공!!");
			con = DriverManager.getConnection(url, id, password);
			System.out.println("데이터베이스 연결 성공 키야!!");
		} catch(ClassNotFoundException e) {
			System.out.println("젠장!! 드라이버를 찾을 수가 없습니다.");
		} catch (SQLException e) {
			System.out.println("연결에 실패했습니다. 포기하세요!!");
		}
		return con;
	}
	
	public static void main(String[] args) throws SQLException {
		Connection con = makeConnection();
		/*Statement stmt = con.createStatement();
		ResultSet rs = stmt.executeQuery("select * from books");
		while(rs.next()) {
			int id = rs.getInt("book_id");
			String title = rs.getString("title");
			System.out.println(id + " " + title);
		}*/
	}
}